<%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="html" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html>
<html>
<html:header title="进货分析按单据详情">

    <link rel="stylesheet" href="${baseUrl}css/public.css" media="all">


    <style type="text/css">
        label{
            display:inline-block;
            width:80px;
            color: #999;
        }

        .info{
            color: #666;
            padding: 2px;
        }
        .layui-card {border:1px solid #f2f2f2;border-radius:5px;}
    </style>

    <script>

        jQuery(function () {

            $("#cancel").click(function () {
                closeSubIframe();
            });
        });

        layui.use(['form', 'table','element'], function () {
            let $ = layui.jquery,
                form = layui.form,
                table = layui.table,
                element = layui.element,
                util = layui.util;

            renderTable();

            $("#search-btn").click(function () {
                table.reload("table", {where:genSearch(),page: {curr: 1}});
            });

            $("#export").click(function () {
                exportExcel();
            });
        });


        function genSearch() {
            let json = getFormJson($("#searchForm"));
            let data = {
                close:false,
                storeId: "${storeId}",
                houseId: "${houseId}",
                date: "${date}",
                search:json.search_order
            };
            return data;
        }

        function renderTable() {
            layui.table.render({
                id:'table',
                elem: '#table',
                totalRow:true,
                url: "${baseUrl}goodsCount/inGoodsAnalysis/getOrderDetail.action",
                where : {
                    close:false,
                    date:"${date}",
                    storeId: "${storeId}",
                    houseId: "${houseId}",
                    time:(new Date()).valueOf()
                },
                cols: [[
                    {width:70,title:"序号",templet:function (d) {
                            return d.LAY_INDEX;
                        }},
                    {field: 'no', width: 150, title: '单据编号',style:"font-size:12px;",templet:'#linkOrderBar'},
                    {field: 'provider', width: 150, title: '供应商名称',style:"font-size:12px;",templet: function (d) {
                            return emptyEntity(d.provider) ? "":d.provider.name;
                        }},
                    {width: 250, title: '进货商品',style:"font-size:12px;", templet: function(d){
                            return genGoodsAndPacket(d.inGoodsGoodsVoList, d.inGoodsPacketVoList);
                        }},
                    {field: 'oldTotalAmt', width: 130, title: '进货额',style:"font-size:12px;",templet: function (d) {
                            return getPrice(d.oldTotalAmt);
                        }},

                    {field: 'otherAmt', width: 130, title: '其他费用',style:"font-size:12px;",templet: function (d) {
                            return getPrice(d.otherAmt);
                        }},
                    {field: 'tax',width: 120, title: '税额',style:"font-size:12px;",templet: function (d) {
                            return getPrice(d.tax);
                        }},
                ]],
                limit: 10,
                page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                    layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                    //,curr: 5 //设定初始在第 5 页
                    ,groups: 5 //只显示 5 个连续页码
                    ,first: false //不显示首页
                    ,last: false //不显示尾页
                },
                done: function(res, curr, count){
                    let oldTotalAmt = 0;
                    let otherAmt = 0;
                    let tax = 0;
                    $.each(res.data, function (i,d) {
                        oldTotalAmt += parseFloat(d.oldTotalAmt);
                        otherAmt += parseFloat(d.otherAmt);
                        tax += parseFloat(d.tax);
                    });

                    setTotalRowWithParent($('[lay-id="table"]'),"oldTotalAmt",getPrice(oldTotalAmt));
                    setTotalRowWithParent($('[lay-id="table"]'),"otherAmt",getPrice(otherAmt));
                    setTotalRowWithParent($('[lay-id="table"]'),"tax",getPrice(tax));
                    setTotalRowWithParent($('[lay-id="table"]'),"0","合计");

                    $(".linkNo").click(function () {
                        openTab($(this).attr("linkTitle"),$(this).attr("linkUrl"));
                    });
                }
            });
        }

        function exportExcel() {
            confirm("是否导出所有的数据?",function () {
                tipLoad("处理中，请稍后");
                post("${baseUrl}goodsCount/inGoodsAnalysis/exportOrderDetailData.action" + genParam(genSearch()),{},function (resp) {
                    closeAll();
                    if (resp.code == 1) {
                        downloadFileByForm("${baseUrl}file/excel/temp/"+resp.data);
                    }  else {
                        errTip(resp.msg);
                    }
                });
            });
        }
    </script>

</html:header>
<body style="margin:0">
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-card">
            <div class="layui-card-header">
                <div class="font16 fontB fontDeepBlue">
                    进货明细
                </div>
            </div>
            <div class="layui-card-body">
                <div class="info"><label>日期:</label>
                    ${date}
                </div>
                <div class="info"><label>门店仓库:</label>
                    <c:choose>
                        <c:when test="${empty storeId}">
                            全部
                        </c:when>

                        <c:when test="${empty houseId}">
                            ${storeName}

                            <span style="padding:0px 4px 0px 4px;color: #c2c2c2"> &gt; </span>
                            全部
                        </c:when>

                        <c:otherwise>
                            ${storeName}

                            <span style="padding:0px 4px 0px 4px;color: #c2c2c2"> &gt; </span>
                            ${houseName}
                        </c:otherwise>
                    </c:choose>
                </div>
            </div>
        </div>

        <form id="searchForm" class="layui-form">
            <div class="layui-input-inline">
                <input type="text" name="search_order" placeholder="搜索编号、供应商名称" class="layui-input" autocomplete="off" style="font-size: 12px;">
            </div>

            <div class="layui-inline">
                <a class="layui-btn" id="search-btn"><i class="layui-icon layui-icon-search"></i></a>
                <a class="layui-btn layui-btn-primary" id="export">导出</a>
            </div>
            <table class="layui-hide" id="table" lay-filter="table" lay-size="sm"></table>
        </form>

        <script type="text/html" id="linkOrderBar">
            {{#  if((_login_user.viewOtherOrder && _login_user.store.sys) || _login_user.id==d.userId){ }}
            <a class="linkNo" href="javascript:;" linkUrl="${baseUrl}inGoods/inGoodsDetail.action?id={{d.id}}" linkTitle="进货单详情" >{{d.no}}</a>
            {{# }else{ }}
            {{d.no}}
            {{# } }}
        </script>
    </div>
</div>
</body>
<html:loading/>
</html>